{extend name="base"/}
{block name="main"}
<style>
    .table>tbody>tr>td{
        text-align: center;
    }
</style>
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="{:url('bargain/index')}" class="n_tab_list">活动列表</a>
            <a href="{:url('bargain/add_bargain')}" class="n_tab_add">添加活动</a>
            <div class="cl"></div>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <form class="Huiform" method="post" action="{:url('bargain/index')}" target="_self">
                <div class="text-c"> 活动名称：
                    <input type="text" class="input-text" value="{$search_text}" style="width:250px" placeholder="输入活动名称"  name="search_text">
                    <button type="submit" class="btn btn-search radius"  name=""><i class="Hui-iconfont">&#xe665;</i> 搜活动</button>
                </div>
            </form>
        </div>
        <table class="table table-border table-bordered table-hover table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="11">活动</th>
            </tr>
            <tr class="text-c">
                <th>活动名称</th>
                <th>活动主图</th>
                <th>原价</th>
                <th>底价</th>
                <th>完成人数</th>
                <th>活动数量</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>消费截至时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                {volist name="list" id="vo" key='k'}
                <tr>
                    <td>{$vo['bargain_name']}</td>
                    <td><img src="{$vo['img_cover']}" width="50"></td>
                    <td>￥{$vo['original_price']}</td>
                    <td>￥{$vo['lowest_price']}</td>
                    <td>{$vo['completed_number']}</td>
                    <td>{$vo['bargain_inventory']}</td>
                    <td>{$vo['star_time']|date='Y-m-d H:i:s',###}</td>
                    <td>{$vo['end_time']|date='Y-m-d H:i:s',###}</td>
                    <td>{$vo['consumption_time']|date='Y-m-d H:i:s',###}</td>
                    <td>
                        {if $vo['bargain_type']==1}
                            <a href="javascript:;" onclick="bargain_status('{$vo.id}','off')"><span class="label label-success radius">正常</span></a>
                        {else}
                        <a href="javascript:;" onclick="bargain_status('{$vo.id}','on')"><span class="label label-danger radius">下架</span></a>
                        {/if}
                    </td>
                    <td>
                        <input onclick="bargain_edit('活动编辑','__CONF_SITE__admin/bargain/bargain_edit&id={$vo.id}','1200','800')" class="btn btn-primary size-S radius" type="button" value="修改">
                        <input type="button" class="btn btn-primary size-S radius" onclick="del('{$vo.id}')" value="删除">
                        <input type="button" class="btn btn-primary size-S radius" onclick="copy_now('wxpath{$k}')" id="wxpath{$k}" data-clipboard-text="yb_shop/pages/kanjia/goods_info/index?id={$vo.id}" value="复制链接">
                    </td>
                </tr>
                {/volist}
            </tbody>
        </table>
    </article>
    <div class="n_page_no">
        {$page}
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function del(id) {
        layer.confirm("确定要删除吗?",function(){
            //此处请求后台程序
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('bargain/bargain_del')}",
                data : {
                    "id" : id,
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('操作成功',{icon:1,time:1000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    /*
     参数解释：
     title	标题
     url		请求的url
     id		需要操作的数据id
     w		弹出层宽度（缺省调默认值）
     h		弹出层高度（缺省调默认值）
     */
    /*活动-状态*/
    function bargain_status(id,key){
        var msg='';
        if(key=='off'){
            msg='确定要下架吗？';
        }else {
            msg='确定要上架吗？';
        }
        layer.confirm(msg,function(){
            //此处请求后台程序
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('bargain/bargain_status')}",
                data : {
                    "id" : id,
                    "key":key
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('操作成功',{icon:1,time:1000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    /*活动-编辑*/
    function bargain_edit(title,url,w,h){
        location.href = url;
        //layer_show(title,url,w,h);
    }
    function copy_now(id) {
        id='#'+id;
        var check=$(id).attr('data-clipboard-text');
        if(check.length<=0){
            layer.msg("链接信息有误", {icon: 2, time: 1000});
            return false;
        }
        var clipboard=new Clipboard(id);
        clipboard.on('success',function(e){
            layer.msg("链接复制成功", {icon: 1, time: 500});
        });
        clipboard.on('error', function(e) {
            layer.msg("链接信息有误", {icon: 2, time: 1000});
        });
    }
</script>
{/block}